package com.fin.zw.aiqas.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.fin.zw.aiqas.service.TaskInfoJobService;
import com.fin.zw.aiqas.service.ExecuteTaskInfoService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class TaskSimpleJob implements SimpleJob {

    private static final Logger log = LoggerFactory.getLogger(TaskSimpleJob.class);

    @Autowired
    private TaskInfoJobService taskInfoJobService;

    @Autowired
    private ExecuteTaskInfoService executeTaskInfoService;

    @Override
    public void execute(ShardingContext shardingContext) {
        String jobName = shardingContext.getJobName();
        log.info("开始启动对应的任务，任务名称是：" + jobName);
        int lastIndexOf = jobName.lastIndexOf("_");
        String taskId = jobName.substring(lastIndexOf + 1);
        //service调用方法
        log.info("启动的任务id：" + taskId);
        if (StringUtils.isNotBlank(taskId)) {
            Long task = Long.valueOf(taskId);
            executeTaskInfoService.sendTaskInfo(task);
        }
    }
}
